package com.supplychain.scm.core.common.version;

import com.supplychain.scm.core.common.version.config.ApiVersionProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ApiWebMvcRegistrations
 * @Description 配置WebMvcRegistrations，启用自定义路由Mapping
 * @createTime 13:08:00 2023/01/05
 */
@RequiredArgsConstructor
public class ApiWebMvcRegistrations implements WebMvcRegistrations {

    private final ApiVersionProperties apiVersionProperties;

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        if (apiVersionProperties.isEnabled()) {
            return new ApiVersionRequestMappingHandlerMapping(apiVersionProperties);
        }
        return null;
    }
}